<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Tells whether the token is of given kind.</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="phptoken.gettokenname.html">« PhpToken::getTokenName</a></li>
      <li style="float: right;"><a href="phptoken.isignorable.html">PhpToken::isIgnorable »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.phptoken.html">PhpToken</a></li>
    <li>Tells whether the token is of given kind.</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="phptoken.is" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PhpToken::is</h1>
  <p class="verinfo">(PHP 8)</p><p class="refpurpose"><span class="refname">PhpToken::is</span> &mdash; <span class="dc-title">Tells whether the token is of given kind.</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-phptoken.is-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>PhpToken::is</strong></span>(<span class="methodparam"><span class="type"><span class="type">int</span>|<span class="type">string</span>|<span class="type">array</span></span> <code class="parameter">$kind</code></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Tells whether the token is of given <code class="parameter">kind</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-phptoken.is-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
     <dt>
<code class="parameter">kind</code></dt>

     <dd>

      <p class="para">
       Either a single value to match the token&#039;s id or textual content, or an array thereof.
      </p>
     </dd>

    
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-phptoken.is-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   A boolean value whether the token is of given kind.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-phptoken.is-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-3826">
   <p><strong>示例 #1 <span class="function"><strong>PhpToken::is()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$token&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PhpToken</span><span style="color: #007700">(</span><span style="color: #0000BB">T_ECHO</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'echo'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$token</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">is</span><span style="color: #007700">(</span><span style="color: #0000BB">T_ECHO</span><span style="color: #007700">));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;-&gt;&nbsp;bool(true)<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$token</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">is</span><span style="color: #007700">(</span><span style="color: #DD0000">'echo'</span><span style="color: #007700">));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;-&gt;&nbsp;bool(true)<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$token</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">is</span><span style="color: #007700">(</span><span style="color: #0000BB">T_FOREACH</span><span style="color: #007700">));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;-&gt;&nbsp;bool(false)<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$token</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">is</span><span style="color: #007700">(</span><span style="color: #DD0000">'foreach'</span><span style="color: #007700">));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;-&gt;&nbsp;bool(false)</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="example-3827">
   <p><strong>示例 #2 Usage with array</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">isClassType</span><span style="color: #007700">(</span><span style="color: #0000BB">PhpToken&nbsp;$token</span><span style="color: #007700">):&nbsp;</span><span style="color: #0000BB">bool&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$token</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">is</span><span style="color: #007700">([</span><span style="color: #0000BB">T_CLASS</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">T_INTERFACE</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">T_TRAIT</span><span style="color: #007700">]);<br />}<br /><br /></span><span style="color: #0000BB">$interface&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PhpToken</span><span style="color: #007700">(</span><span style="color: #0000BB">T_INTERFACE</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'interface'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">isClassType</span><span style="color: #007700">(</span><span style="color: #0000BB">$interface</span><span style="color: #007700">));&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;-&gt;&nbsp;bool(true)<br /><br /></span><span style="color: #0000BB">$function&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PhpToken</span><span style="color: #007700">(</span><span style="color: #0000BB">T_FUNCTION</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'function'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">isClassType</span><span style="color: #007700">(</span><span style="color: #0000BB">$function</span><span style="color: #007700">));&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;-&gt;&nbsp;bool(false)</span>
</span>
</code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-phptoken.is-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="function.token-name.html" class="function" rel="rdfs-seeAlso">token_name()</a> - 获取提供的 PHP 解析器代号的符号名称</span></li>
  </ul>
 </div>

</div></div></div></body></html>